package com.ruoyi.invest.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invest.domain.TbInvestLog;
import com.ruoyi.invest.service.ITbInvestLogService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 投资日志Controller
 * 
 * @author ruoyi
 * @date 2023-01-14
 */
@RestController
@RequestMapping("/log")
@CrossOrigin
public class TbInvestLogController extends BaseController
{
    @Autowired
    private ITbInvestLogService tbInvestLogService;

    /**
     * 查询投资日志列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbInvestLog tbInvestLog)
    {
        startPage();
        List<TbInvestLog> list = tbInvestLogService.selectTbInvestLogList(tbInvestLog);
        return getDataTable(list);
    }

    /**
     * 导出投资日志列表
     */
    @Log(title = "投资日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbInvestLog tbInvestLog)
    {
        List<TbInvestLog> list = tbInvestLogService.selectTbInvestLogList(tbInvestLog);
        ExcelUtil<TbInvestLog> util = new ExcelUtil<TbInvestLog>(TbInvestLog.class);
        util.exportExcel(response, list, "投资日志数据");
    }

    /**
     * 获取投资日志详细信息
     */
    @GetMapping(value = "/{investLogId}")
    public AjaxResult getInfo(@PathVariable("investLogId") Long investLogId)
    {
        return success(tbInvestLogService.selectTbInvestLogByInvestLogId(investLogId));
    }

    /**
     * 新增投资日志
     */
    @Log(title = "投资日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInvestLog tbInvestLog)
    {
        return toAjax(tbInvestLogService.insertTbInvestLog(tbInvestLog));
    }

    /**
     * 修改投资日志
     */
    @Log(title = "投资日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInvestLog tbInvestLog)
    {
        return toAjax(tbInvestLogService.updateTbInvestLog(tbInvestLog));
    }

    /**
     * 删除投资日志
     */
    @Log(title = "投资日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{investLogIds}")
    public AjaxResult remove(@PathVariable Long[] investLogIds)
    {
        return toAjax(tbInvestLogService.deleteTbInvestLogByInvestLogIds(investLogIds));
    }
}
